package com.obelisco.vista.imagen;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ProxyOutputStream;

import echopointng.ExtentEx;

import nextapp.echo2.app.ApplicationInstance;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.ResourceImageReference;
import nextapp.echo2.app.StreamImageReference;

public class ByteArrayImageReference extends  StreamImageReference {
	
	private String contentType;
	private byte[] data;
	
	public ByteArrayImageReference(byte[] data,String contentType) {
		super();
		this.contentType = contentType;
		this.data = data;
	}
	
	public ByteArrayImageReference(byte[] data) {
		super();
		this.contentType = "image/jpg";
		this.data = data;
	}

	
    String id = ApplicationInstance.generateSystemId();

    @Override
    public String getContentType() {
        return contentType;
    }

    @Override
    public void render(OutputStream out) throws IOException {
        ByteArrayInputStream in = new ByteArrayInputStream(data);
        IOUtils.copy(in, out);
    }

    public String getRenderId() {
        return id;
    }
    

}
